<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  searchEngine
 */

class m_searchEngine_actions_block_front_SearchResultAction extends f_core_Action
{
	public function execute()
	{
		$words = $this->getRequestParameter("keywords");

        $page = $this->getRequestParameter("urlSuffix", 1);

        if(is_null($words) || $words == "")
        {
            $words = $this->getContext("searchEngine");
        }

        if(is_null($words) && $page != "" || intval($page) <= 0)
        {
            $this->getContext("currentPage")->setRedirect("404");
        }

        if(!is_null($words) && $words != "")
        {
            $this->getContext("currentPage")->setMetaTitle("Résultat de la recherche pour : ".$words);
            f_core_Context::getInstance()->setContext("searchEngine", $words);
            $results = m_searchEngine_services_searchService::getInstance()->addWordToSearch($words)->getResults($page);
            $this->addToModel("page", $this->getContext("currentPage"));
            $this->addToModel("words", $words);
            $this->addToModel("results", $results);
        }

		$this->setView('success');
	}	
}